package com.shansun.event

import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.ActorSystem
import akka.actor.Props
import utils.GsonHelper

/**
 * @author:     lanbo <br>
 * @version:    1.0  <br>
 * @date:   	2012-4-10
 */
class EventActor extends Actor with ActorLogging {
    def receive = {
        case event: Event => EventEngine.getPersistent().save(event)
        // case EventType.STOP => context.stop(self)
        // case EventType.SHUTDOWN => context.system.shutdown(); log.error("Shutting down!")
        case msg: String => log.info(msg)
        case unknown: Any => log.warning("Unknown Message Content: \n" + GsonHelper.mkString(unknown))
    }
}

object EventActor {
    val system = ActorSystem("EventSystem")

    val eventActor = system.actorOf(Props[EventActor], name = "EventActor")

    def emit(obj: Any) = {
        eventActor ! obj
    }
}